﻿using Ledict.Core.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ledict.ConditionExtract.DAL
{
    public class SYS_CaseTypeDAL
    {
        /// <summary>
        /// 获取所有案件类型的父级
        /// </summary>
        /// <returns></returns>
        public DataTable GetCaseTypeList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"  select CaseTypeID,CT_Name,CT_Code from dbo.SYS_CaseType where CT_Sign = 1 and (CT_Code = 'a' or CT_Code='b') ");
            Database oBase = DatabaseFactory.CreateDatabase("JudgeDoc");
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());
            DataTable OtB = oBase.ExecuteDataSet(oCmd).Tables[0];
            if (OtB.Rows.Count > 0)
            {
                return OtB;
            }
            else
            {
                return new DataTable();
            }
        }

        /// <summary>
        /// 根据caseTypeId获取当前节点的子集
        /// </summary>
        /// <param name="caseTypeId"></param>
        /// <returns></returns>
        public DataTable GetCaseTypeListByID(string caseTypeId)
        {           
            string strSql=string.Format(@" select CaseTypeID,CT_Name,CT_Code from dbo.SYS_CaseType where CT_ParentID = '{0}' and (CT_Code = 'a1' or CT_Code = 'b1')", caseTypeId);
            Database oBase = DatabaseFactory.CreateDatabase("JudgeDoc");
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());
            DataTable OtB = oBase.ExecuteDataSet(oCmd).Tables[0];
            if (OtB.Rows.Count > 0)
            {
                return OtB;
            }
            else
            {
                return new DataTable();
            }
        }

        /// <summary>
        /// 获取sysCaseType数据
        /// </summary>
        /// <returns></returns>
        public DataTable GetCaseTypeData()
        {
            string strSql = " select CaseTypeID as ID,CT_Name as Name,CT_Code as Code,CT_ParentID as ParentID from SYS_CaseType ";
            Database oBase = DatabaseFactory.CreateDatabase("JudgeDoc");
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());
            DataTable OtB = oBase.ExecuteDataSet(oCmd).Tables[0];
            if (OtB.Rows.Count > 0)
            {
                return OtB;
            }
            else
            {
                return new DataTable();
            }
        }

        // 
    }
}
